// YCOAConfiguration
// Mac Radigan

package ycoa.configuration

import sys.utilities.ResourceManager
import org.apache.log4j.xml.DOMConfigurator

public class YCOAConfiguration {
  
  public ConfigObject config
  private static YCOAConfiguration ref = null
  private resourceManager = new ResourceManager()

  private YCOAConfiguration() {
    initialize()
  }

  public static YCOAConfiguration getInstance() {
     if(null==ref) {
        ref = new YCOAConfiguration()
     }
     return ref
  }

  public String getRoot() {
    return "${resourceManager.getRootDirectory().getAbsolutePath()}"
  }

  public String getWebRoot() {
    return "${resourceManager.getRootDirectory().getAbsolutePath()}/webapps/ycoa"
  }

  public initialize() {
    def environment = System.getenv("MODUS_OPERANDI")
    println "MODUS_OPERANDI: ${environment}"
    resourceManager.extractResource("res/ycoa", new File("."))
    DOMConfigurator.configure("config/log4j.xml")
    def ycoaConf = null
    def configSlurper = null
    if(null!=environment) {
      configSlurper = new ConfigSlurper(environment)
    } else {
      configSlurper = new ConfigSlurper()
    }
    config = configSlurper.parse(new File("config/ycoa.conf").toURL())
  }
  
  public static ConfigObject getConfiguration() {
    return getInstance().config
  }

}

// *EOF*
